/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trombinoscope.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import javax.servlet.ServletContext;
import trombinoscope.modele.Etudiant;
import trombinoscope.modele.EtudiantDAO;

/**
 *
 * @author jef
 */
public class servletModifFiche extends HttpServlet {

    public void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        try 
        {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
        
            boolean statut = (Boolean)getServletContext().getAttribute("adminUser"); // récupération du statut
           
            String idEtudiant = request.getParameter("idetudiant");
            Integer idEtudiantInt = Integer.parseInt(idEtudiant);            
            Etudiant etudiantConcerne = EtudiantDAO.getEtudiantByIdEtudiant(idEtudiantInt);
           
            // récupèration du contexte de l'application
            ServletContext context = getServletContext();                    
            context.setAttribute("etudiant", etudiantConcerne);
            context.setAttribute("isAdminUser", statut);
                     
            request.getRequestDispatcher("ficheModifEtudiant.jsp").forward(request, response);
                     
        } 
        
        catch (SQLException e) 
        {	
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<p><strong> Erreur avec la base. </strong>");
            out.println("<p> <a href= \"./trombiListeEtudiants.jsp \"></a> </p>");
            out.println("Cause de l'erreur : " + e.getCause());
		
        }
    }
      @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {       
            processRequest(request, response);          
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {        
            processRequest(request, response);        
    }    
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
